package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.AccountLockVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户账户管理")
@RestController
@RequestMapping("api/account")
@SuppressWarnings({"all"})
public class UserAccountApiController {

	@Autowired
	private UserAccountService userAccountService;

	@Autowired
	private RechargeInfoService rechargeInfoService;

	/**
	 * 获取账户可用余额
	 * @return
	 */
	@GetMapping("/userAccount/getAvailableAmount")
	@GuiGuLogin
	public Result<BigDecimal> getAvailableAmount(){
		BigDecimal bigDecimal = userAccountService.getAvailableAmount();
		return Result.ok(bigDecimal);
	}

	/**
	 * 检查及锁定账户金额
	 * @param accountLockVo
	 * @return
	 */
	@PostMapping("/userAccount/checkAndLock")
	public Result checkAndDeduct(@RequestBody AccountLockVo accountLockVo){
		userAccountService.checkAndLock(accountLockVo);
		return Result.ok();
	}

	@GetMapping("/rechargeInfo/getRechargeInfo/{orderNo}")
	public Result<RechargeInfo> getRechargeInfo(@PathVariable String orderNo){
		RechargeInfo rechargeInfo = rechargeInfoService.getRechargeInfo(orderNo);
		return Result.ok(rechargeInfo);
	}
}

















